﻿<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Blabber.Client"
    x:Class="Blabber.Client.WindowChat" WindowStartupLocation="Manual"
    Title="Chat Window" Height="318" Width="485" Loaded="Window_Loaded" xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">

    <Window.Resources>
		<local:StringConcatenationConverter x:Key="stringConcatConverter" />
		<local:MessageItemSizeConverter x:Key="messageItemSizeConverter" />
		<local:PictureValueConverter x:Key="pictureValueConverter" />

		<Style x:Key="messageItemStyle" TargetType="ListBoxItem">
			<Setter Property="Foreground" Value="Black"></Setter>

			<Style.Triggers>
				<Trigger Property="ListBoxItem.IsSelected" Value="True">
					<Setter Property="ListBoxItem.Foreground" Value="Black" />
					<Setter Property="ListBoxItem.Background" Value="#FFFFFFFF" />
				</Trigger>
			</Style.Triggers>
		</Style>
		
		<DataTemplate x:Key="DataTemplateMessageItem">
                
			<Border Width="{Binding ActualWidth, Converter={StaticResource messageItemSizeConverter}, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type ListBox}}}" 
				HorizontalAlignment="Stretch" CornerRadius="3" BorderBrush="Black" BorderThickness="1" Margin="1,3,1,3">
				<Grid Name="dataGrid" Margin="0" HorizontalAlignment="Stretch" Width="Auto">
					<Grid.RowDefinitions>
						<RowDefinition Height="Auto" />
					</Grid.RowDefinitions>

					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="Auto"/>
						<ColumnDefinition />
					</Grid.ColumnDefinitions>
				
					<Image Source="{Binding Path=Image, Converter={StaticResource pictureValueConverter}}" 
						HorizontalAlignment="Stretch" Height="32" Width="32" Stretch="Uniform" Grid.RowSpan="1" Margin="3,3,6,3" VerticalAlignment="Stretch">
						<Image.BitmapEffect>
							<DropShadowBitmapEffect/>
						</Image.BitmapEffect>
					</Image>
					
					<Grid Grid.Column="1" Margin="3,3,3,3" HorizontalAlignment="Left" >
						<Grid.RowDefinitions>
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
						</Grid.RowDefinitions>
						
						<TextBlock TextWrapping="Wrap" FontWeight="Bold" FontSize="14" HorizontalAlignment="Left">
							<TextBlock.Text>
								<MultiBinding Converter="{StaticResource stringConcatConverter}">
									<Binding Path="From" />
									<Binding Source=" @ " />
									<Binding Path="MessageTime" />
								</MultiBinding>
							</TextBlock.Text>
						</TextBlock>
						
						<TextBox Grid.Row="1" IsReadOnly="True"	Text="{Binding Body}" 
							HorizontalAlignment="Left" TextWrapping="Wrap" FontSize="12" Margin="3,0,0,0" Style="{DynamicResource TextBoxStyleMessage}"/>
					</Grid>
				</Grid>
            </Border>
                
        </DataTemplate>
    	<LinearGradientBrush x:Key="TextBoxBorder" EndPoint="0,20" StartPoint="0,0" MappingMode="Absolute">
    		<GradientStop Color="#ABADB3" Offset="0.05"/>
    		<GradientStop Color="#E2E3EA" Offset="0.07"/>
    		<GradientStop Color="#E3E9EF" Offset="1"/>
    	</LinearGradientBrush>
    	<Style x:Key="TextBoxStyleMessage" BasedOn="{x:Null}" TargetType="{x:Type TextBox}">
    		<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    		<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
    		<Setter Property="BorderBrush" Value="{StaticResource TextBoxBorder}"/>
    		<Setter Property="BorderThickness" Value="1"/>
    		<Setter Property="Padding" Value="1"/>
    		<Setter Property="AllowDrop" Value="true"/>
    		<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    		<Setter Property="Template">
    			<Setter.Value>
    				<ControlTemplate TargetType="{x:Type TextBox}">
    					<Microsoft_Windows_Themes:ListBoxChrome SnapsToDevicePixels="true" x:Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,0,0,0" RenderFocused="{TemplateBinding IsKeyboardFocusWithin}" RenderMouseOver="{TemplateBinding IsMouseOver}">
    						<ScrollViewer SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" x:Name="PART_ContentHost" Background="{x:Null}"/>
    					</Microsoft_Windows_Themes:ListBoxChrome>
    					<ControlTemplate.Triggers>
    						<Trigger Property="IsEnabled" Value="false">
    							<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
    							<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
    						</Trigger>
    					</ControlTemplate.Triggers>
    				</ControlTemplate>
    			</Setter.Value>
    		</Setter>
    	</Style>
    </Window.Resources>

    <Grid ScrollViewer.VerticalScrollBarVisibility="Disabled">
        <Grid.RowDefinitions>
			<RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
           
        </Grid.RowDefinitions>

		<Expander Name="detailExpander" Header="Details" IsExpanded="True" Margin="3,3,3,3">
			<Grid>
				<Grid.RowDefinitions>
					<RowDefinition Height="Auto" />
					<RowDefinition Height="Auto" />
				</Grid.RowDefinitions>

				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition />
				</Grid.ColumnDefinitions>

				<Border Grid.RowSpan="2" Margin="6,6,6,6" Background="{x:Null}" BorderBrush="#FFC3C2C2" BorderThickness="1,1,0,0" CornerRadius="2,2,2,2">
					<Image Source="{Binding Path=Image, Converter={StaticResource pictureValueConverter}}" 
							HorizontalAlignment="Stretch" Height="64" Width="64" Stretch="Uniform" VerticalAlignment="Stretch">
						<Image.BitmapEffect>
							<DropShadowBitmapEffect/>
						</Image.BitmapEffect>
					</Image>
				</Border>
				
				<TextBlock Margin="6,6,6,6" Grid.Column="1" Text="{Binding Path=Name}" FontSize="18" FontWeight="Bold" />
				<TextBlock Margin="6,6,6,6" Grid.Row="1" Grid.Column="1" Text="{Binding Path=JID}" FontSize="16" />
			</Grid>
		</Expander>

		<ListBox Grid.Row="1" Name="listBoxMessages" ItemsSource="{Binding}" ItemTemplate="{DynamicResource DataTemplateMessageItem}" Margin="3,3,3,3"
             VerticalAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Auto"
             ItemContainerStyle="{StaticResource messageItemStyle}"
             VerticalContentAlignment="Stretch" ScrollViewer.CanContentScroll="False" MouseDoubleClick="messageListBox_MouseDoubleClick">

			<ListBox.Resources>
				<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FFFFFFFF"/>
			</ListBox.Resources>
		</ListBox>

		<Grid Name="chatTextGrid" VerticalAlignment="Stretch" Grid.Row="2" ShowGridLines="False">
        	<Grid.ColumnDefinitions>
				<ColumnDefinition />
				<ColumnDefinition Width="Auto" />
			</Grid.ColumnDefinitions>
			
    		<TextBox Name="messageSend" Margin="3,3,3,3" TextWrapping="Wrap" SpellCheck.IsEnabled="True" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"/>
            
    		<Button Grid.Column="1" IsDefault="True" Click="Button_Click" HorizontalAlignment="Right" Margin="3,3,3,3" 
                    Width="Auto" Content="Send" HorizontalContentAlignment="Right" VerticalContentAlignment="Stretch"/>
    	</Grid>
    </Grid>
</Window>
